#!/usr/bin/env python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license.php 

"""
Scrapes noslang.com to build a dict of slang words/translations, saves to csv
"""

import csv
import re
import sys
import urllib

DICTURL = 'http://www.noslang.com/dictionary/full'
OUTPUT = 'slangdict.csv'
PATTERN = '<a\sname="([^"]*)"></a><abbr\stitle="([^"]*)">'


def FetchDict():
  page = urllib.urlopen(DICTURL)
  pagetext = page.read()
  page.close()
  words = re.findall(PATTERN, pagetext)
  output = open(OUTPUT, 'w')
  csv_writer = csv.writer(output)
  csv_writer.writerows(words)
  output.close()
